package com.happy.sky.concurrent.thread.safety;

import java.util.HashMap;
import java.util.Map;

/**
 * @name: WrongInit <tb>
 * @title: 发布和初始化导致线程安全问题  <tb>
 * @author: cuixinfu@51play.com <tb>
 * @date: 2020/8/13 10:22 <tb>
 */
public class WrongInit {

    private Map<Integer, String> students;

    public WrongInit() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                students = new HashMap<>();
                students.put(1, "王小美");
                students.put(2, "钱二宝");
                students.put(3, "周三");
                students.put(4, "赵四");
            }
        }).start();
    }

    public Map<Integer, String> getStudents() {
        return students;
    }

    public static void main(String[] args) throws InterruptedException {
        WrongInit multiThreadsError6 = new WrongInit();
        System.out.println(multiThreadsError6.getStudents().get(1));

    }
}
